import { request } from '@/utils/request'
import type { ApiResponse } from '@/types/api'

export interface ProjectMember {
  user_id: string
  role: string
  joined_at: string
  permissions: string[]
}

export interface UpdateProjectMemberParams {
  role?: string
  permissions?: string[]
}

// 更新项目成员
export function updateProjectMember(
  projectId: string, 
  userId: string, 
  data: UpdateProjectMemberParams
): Promise<ApiResponse<void>> {
  return request({
    url: `/projects/${projectId}/members/${userId}`,
    method: 'put',
    data
  })
}

// 获取项目成员列表
export function getProjectMembers(projectId: string): Promise<ApiResponse<ProjectMember[]>> {
  return request({
    url: `/projects/${projectId}/members`,
    method: 'get'
  })
}

// 添加项目成员
export function addProjectMember(
  projectId: string, 
  data: { user_id: string; role: string; permissions?: string[] }
): Promise<ApiResponse<void>> {
  return request({
    url: `/projects/${projectId}/members`,
    method: 'post',
    data
  })
}

// 移除项目成员
export function removeProjectMember(
  projectId: string, 
  userId: string
): Promise<ApiResponse<void>> {
  return request({
    url: `/projects/${projectId}/members/${userId}`,
    method: 'delete'
  })
}